package hbi.task.as3
{
	import hbi.domain.as3.AS3Gateway;
	
	public class TaskAgentLifeScript
	{
		
		private var agentClass:Class;
		
		[ArrayElementType("hbi.task.as3::AgentMethodInvocation")]
		private var invocations:Array;
		
		public function TaskAgentLifeScript(agentClass:Class, invocations:Array)
		{
			this.agentClass = agentClass;
			this.invocations = invocations;
		}
		
		public function liveUp(gateway:AS3Gateway):void
		{
			const agent:Object = new agentClass();
			agent.arrived(gateway);
			for each (var invocation:AgentMethodInvocation in invocations)
			{
				var m:Function = agent[invocation.method] as Function;
				m.apply(agent, invocation.arguments);
			}
			agent.finishTask(gateway);
		}
	}
}
